package net.maku.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.biz.convert.BizMailboxConvert;
import net.maku.biz.entity.BizMailboxEntity;
import net.maku.biz.query.BizMailboxQuery;
import net.maku.biz.vo.BizMailboxVO;
import net.maku.biz.dao.BizMailboxDao;
import net.maku.biz.service.BizMailboxService;
import net.maku.talent.entity.HonorCommunityEntity;
import net.maku.talent.vo.HonorCommunityVO;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 主席信箱
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-29
 */
@Service
@AllArgsConstructor
public class BizMailboxServiceImpl extends BaseServiceImpl<BizMailboxDao, BizMailboxEntity> implements BizMailboxService {

    private final BizMailboxDao mailboxDao;
    @Override
    public PageResult<BizMailboxVO> page(BizMailboxQuery query) {
//        IPage<BizMailboxEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
//
//        return new PageResult<>(BizMailboxConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());

        IPage<BizMailboxEntity> pageParams = getPage(query);
        QueryWrapper<HonorCommunityVO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(query.getMemberName()),"m.real_name",query.getMemberName());
        queryWrapper.orderByDesc("id");
        IPage<BizMailboxVO> page = mailboxDao.selectPageList(pageParams,queryWrapper);
        return new PageResult<>(page.getRecords(),page.getTotal());
    }

    private LambdaQueryWrapper<BizMailboxEntity> getWrapper(BizMailboxQuery query){
        LambdaQueryWrapper<BizMailboxEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(BizMailboxVO vo) {
        BizMailboxEntity entity = BizMailboxConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(BizMailboxVO vo) {
        BizMailboxEntity entity = BizMailboxConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}